﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.MembershipService;
using Avatar.Model;
using System.Web.Security;

public partial class UserControl_PersonalLogin : System.Web.UI.UserControl
{
    public string _username = string.Empty;
    public string _lastLogin = string.Empty;
    public string _registerTime = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var _user = Membership.GetUser();
            if (_user != null)
            {
                _username = _user.UserName;
                _registerTime = _user.CreationDate.ToString();
                _lastLogin = _user.LastActivityDate.ToString();
        }}
    }
    protected void logout_Click(object sender, EventArgs e)
    {
        LoginManager.Logout();
    }
    protected void btn_login_Click(object sender, ImageClickEventArgs e)
    {
        string _pwd = ((TextBox)LoginView1.FindControl("txt_Pwd")).Text;
        string _email = ((TextBox)LoginView1.FindControl("txt_Name")).Text;
        string _vCode = ((TextBox)LoginView1.FindControl("txt_VCode")).Text;
        bool _remeberMe = ((CheckBox)LoginView1.FindControl("RemeberMe")).Checked;

        try
        {
            LoginManager.Login(_email, _pwd, _vCode, _remeberMe);
        }
        catch (Exception _e)
        {
            Label _lbl_Error = (Label)LoginView1.FindControl("lbl_Error");
            _lbl_Error.Text = "登录失败：" + _e.Message;
        }
    }
}
